var _oArea;


var UNDEFINED_FORM_TYPE = 0;
var CREATE_FORM		= 1;
var UPDATE_FORM		= 2;
var READ_ONLY_FORM	= 3;
var DISABLED_FORM	= 4;
var QUICK_CREATE_FORM = 5;
var BULK_EDIT_FORM	= 6;

function loadArea(sArea, sParams, sUrl, bIsvMode)
{
    if (!_oArea) _oArea = tdAreas.firstChild;

    var o = document.all(sArea);
    if(o && o.length)
    {
    var i;
    for(i=0; i<o.length; i++)
    {
        if(o[i].params == sParams)
        {
            o = o[i];
            break;
        }
    }

    if(i==o.length) o = null;
    }
    else if(o && o.params != sParams)
    {
        o = null;
    }
    if (o)
    {
        if (o == _oArea) return false;
        _oArea.style.display = "none";
        o.style.display = "inline";
    }
    else
    {
        var sBaseUrl = "areas.aspx";

        if (sUrl)
        {
            sBaseUrl = sUrl;
        }

        if(typeof(bIsvMode) != "undefined" && bIsvMode == true)
        {
            sBaseUrl = SetQueryString(sBaseUrl, "id", crmFormSubmit.crmFormSubmitId.value);
            sBaseUrl = SetQueryString(sBaseUrl, "type", crmFormSubmit.crmFormSubmitObjectType.value);
            sBaseUrl = SetQueryString(sBaseUrl, "typename", crmFormSubmit.crmFormSubmitObjectTypeName.value);
        }
        else
        {
            sBaseUrl = SetQueryString(sBaseUrl, "oId", crmFormSubmit.crmFormSubmitId.value);
            sBaseUrl = SetQueryString(sBaseUrl, "oType", crmFormSubmit.crmFormSubmitObjectType.value);
        }

        sBaseUrl = SetQueryString(sBaseUrl, "security", crmFormSubmit.crmFormSubmitSecurity.value);

        if (sParams)
        {
            sBaseUrl += sParams;
        }

        sBaseUrl = SetQueryString(sBaseUrl, "tabSet", sArea);
        
        html = "<iframe allowTransparency='-1' src='" + sBaseUrl;
        html += "' id='" + sArea + "Frame' scrolling='no' isArea='1' width='100%' height='100%' frameborder='0'></iframe>";

        o = document.createElement("DIV");
        o.id = sArea;
        if(!IsNull(sParams))
        {
            o.params = sParams;
        }
        o.innerHTML = html;

        _oArea.style.display = "none";

        tdAreas.appendChild(o);
    }
    _oArea = o;

    ResetBreadcrumb(event.srcElement);

    var button = document.all("_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup");
    if (button != null)
    {
        if (sArea == "areaForm")
        {
            button.disabled = false;
        }
        else
        {
            button.disabled = true;
        }
    }
}

function ResetBreadcrumb(selectedNav)
{
    var imgNavigation = findNavigationComponent(selectedNav, "IMG");
    var textNavigation = findNavigationComponent(selectedNav, "NOBR");
    var imgBreadcrumb = document.all("leftNavBreadcrumbImg");
    var textBreadcrumb = document.all("leftNavBreadcrumbText");
    if ((imgBreadcrumb != null) && (imgNavigation != null))
    {
        imgBreadcrumb.src = imgNavigation.src;
        imgBreadcrumb.style.backgroundImage = imgNavigation.style.backgroundImage;
        imgBreadcrumb.style.backgroundPositionY = imgNavigation.style.backgroundPositionY;
        imgBreadcrumb.style.backgroundPositionX = imgNavigation.style.backgroundPositionX;
        imgBreadcrumb.style.clip = imgNavigation.style.clip;
        imgBreadcrumb.style.height = imgNavigation.style.height;
        imgBreadcrumb.style.width = imgNavigation.style.width;
    }
    if ((textBreadcrumb != null) && (textNavigation != null))
    {
        textBreadcrumb.innerText = textNavigation.innerText;
    }
}

function findNavigationComponent(eventSourceElement, elementTagName)
{

var		parentElement = null;
if ("A" == eventSourceElement.tagName)
{
parentElement = eventSourceElement;
}
else
{
parentElement = eventSourceElement.parentElement;
}
return parentElement.getElementsByTagName(elementTagName)[0];
}

function addActivityTo(iType, spId, spType, spName, sPartyId, sPartyType, sPartyName, sLocation, sContentId)
{
var iX, iY;
var sUrl = "";



if (spId != null && spType != null && iType != CampaignResponse)
{

sUrl += "&pId=" + spId;
sUrl += "&pType=" + spType;
sUrl += "&pName=" + CrmEncodeDecode.CrmUrlEncode(spName);
}


if (!IsNull(sPartyId))
{
sUrl += "&partyid=" + sPartyId;
sUrl += "&partytype=" + sPartyType;
sUrl += "&partyname=" + CrmEncodeDecode.CrmUrlEncode(sPartyName);
sUrl += "&partyaddressused=";
sUrl += "&contactInfo=" + CrmEncodeDecode.CrmUrlEncode(sLocation);
}

if (!IsNull(sContentId))
{
sUrl += "&contentId=" + sContentId;
}


if (sUrl.substr(0, 1) == "&")
{
sUrl = "?" + sUrl.substr(1);
}

openFrmObj(sUrl, "", iType);
}
